<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
ini_set('display_errors', '1');
header("Content-type:text/html;charset=utf-8");

class Photo extends a_base {

    public function __construct(){
        parent::__construct();
    }

    public function index(){
        $where = array();
        $page = isset($_GET['page'])?$_GET['page']:1;//当前页
        $cntArr = $this->m_public->getRowInfo('config',$where,'count(1) as cnt');
        $arr = array (
            'page' => $page,//当前页
            'page_size' => 10,     //分页总大小
            'total' => $cntArr['cnt']//总记录数
        );
        $where['limit'] = 10;
        $where['offset'] = ($page - 1) * 10;
        $where['from'] = 'photo';
        $data['info'] = $this->m_public->get_list($where);
        foreach($data['info'] as $key=>$val){
            $class_info = $this->m_public->getRowInfo('class',array('classid'=>$val['classid']));
            $data['info'][$key]['classname'] = $class_info['classname'];
            $admin_info = $this->m_public->getRowInfo('admin',array('adminid'=>$val['adminid']));
            $data['info'][$key]['adminname'] = $admin_info['adminname'];
        }

        $data['pagination'] = new pagination($arr);
        $this->load->view('photo/index',$data);
    }

    public function photo_add($photoid){
        $data['class'] = $this->m_public->getAllInfo('class');
        if($photoid){
            $data['info'] = $this->m_public->getRowInfo('photo',array('photoid'=>$photoid));
        }
        $this->load->view('photo/add',$data);
    }

    public function photo_action($photoid){
        $data = $this->input->post();
        if($photoid){
            $this->m_public->editInfo(array('photoid'=>$photoid), $data, 'photo');
        }else{
            $data['adminid'] = $this->session->userdata['user_id'];
            $data['addtime'] = date('Y-m-d H:i:s');
            $this->m_public->addRowInfo('photo',$data);
        }
        redirect('photo/index');
    }

    public function photopic_index($photoid){
        $data['photoid'] = $photoid;
        $where = array('photoid'=>$photoid);
        $page = isset($_GET['page'])?$_GET['page']:1;//当前页
        $cntArr = $this->m_public->getRowInfo('photopic',$where,'count(1) as cnt');
        $arr = array (
            'page' => $page,//当前页
            'page_size' => 10,     //分页总大小
            'total' => $cntArr['cnt']//总记录数
        );
        $condition['where'] = $where;
        $condition['limit'] = 10;
        $condition['offset'] = ($page - 1) * 10;
        $condition['from'] = 'photopic';
        $data['info'] = $this->m_public->get_list($condition);
        foreach($data['info'] as $key=>$val){
            $photo_info = $this->m_public->getRowInfo('photo',array('photoid'=>$val['photoid']));
            $data['info'][$key]['photoname'] = $photo_info['photoname'];
            $admin_info = $this->m_public->getRowInfo('admin',array('adminid'=>$val['adminid']));
            $data['info'][$key]['adminname'] = $admin_info['adminname'];
        }

        $data['pagination'] = new pagination($arr);

        $this->load->view('photo/photopic_index',$data);
    }

    public function photopic_add($photoid){
        $data['photos'] = $this->m_public->getAllInfo('photo');
        $data['photoid'] = $photoid;
        $this->load->view('photo/photopic_add',$data);
    }

    public function photopic_action($photoid){
        $data = $this->input->post();
        $data['photoid'] = $photoid;
        $data['adminid'] = $this->session->userdata['user_id'];
        $data['addtime'] = date('Y-m-d H:i:s');
        $this->m_public->addRowInfo('photopic',$data);
        redirect('photo/photopic_index/'.$photoid);
    }

    public function delete_info($url,$parmykey,$table,$ids)
    {
        if(!$ids){
            redirect("photo/$url");
        }
        $idArr = explode('.', $ids);
        foreach($idArr as $k=>$v){
            $res = $this->m_public->delInfo($table,array($parmykey=>$v));
        }
        redirect("photo/$url");
    }

}
